var Koa        = require('koa');
var logger     = require('koa-logger');
var config     = require('./config');
var prototype  = require('./utils/prototype');
var route      = require('./utils/routes');
var foo        = require('./utils/function');

var app        = Koa();
/* 声明全局配置和函数 */
global.C = config;
global.F = foo;

app.keys = config.data_auth_key;
app.jsonSpaces = 0

app.use(function *(next){
	this.set(C.header);
	var start = new Date;
	global.NOW_TIME = F.now();
	yield next;
	var ms = new Date - start;
	console.log('>>%s [%s] %s %s -[%sms] >> %s', this.ip, start.Format('hh:mm:ss'), this.method, this.url, ms, this.type);
});

route(app);

app.listen(C.port, function () {
	console.log('App Running at port ' + C.port);
});